function methodChange(method) {
	var p1 = $(method).children('option:selected').val();// 这就是selected的值
	// alert(p1);
	if ("POST" == p1) {
		$("#bodyContol").show();
	} else if ("GET" == p1) {
		$("#bodyContol").hide();
	}
}

var addBefore = "";
var addAfter = "";
$(document)
		.ready(
				function() {
					$("#bodyContol").hide();
					$("#rawAll").hide();
					$("#rawSelect").hide();
					$("#methodControl").change(function() {
						methodChange(this);
					});
					$("#rawButton").click(
							function() {
								$(this).removeClass("btn-default").addClass(
										"active");
								$("#xfuButton").removeClass("active").addClass(
										"btn-default");
								// alert($(this).attr("name"));
								// x-www-form-urlencoded
								$("#entitis_value").val("raw");
								$("#rawContent").attr("name", "entities.data");

								$("#xfuAll").hide();
								$("#rawAll").show();
								$("#rawSelect").show();
							});
					$("#xfuButton").click(
							function() {
								$("#xfuButton").removeClass("btn-default")
										.addClass("active");
								$("#rawButton").removeClass("active").addClass(
										"btn-default");

								$("#entitis_value")
										.val("x-www-form-urlencoded");
								$("#rawContent").attr("name", "");

								$("#rawAll").hide();
								$("#rawSelect").hide();
								$("#xfuAll").show();
							});
					$("#runBeforeAdd")
							.click(
									function() {
										if (addBefore == "") {
											// alert("添加类为空，发起请求！");
											$
													.ajax({
														type : "POST",
														url : "getInitBefore.action",
														data : "",
														dataType : "json",
														success : function(json) {
															// alert(json.initBeforeJson);
															addBefore = jQuery
																	.parseJSON(json.initBeforeJson);
															var addClass = "";
															var addMethod = "";
															$
																	.each(
																			addBefore,
																			function(
																					key,
																					values) {
																				addClass += "<option>"
																						+ key
																						+ "</option>";
																				// $
																				// .each(
																				// values,
																				// function(
																				// i,
																				// value)
																				// {
																				// addMethod
																				// +=
																				// "<option
																				// id=\"beforeOption\"
																				// title=\""
																				// +
																				// value
																				// .split(",")[1]
																				// +
																				// "\">"
																				// +
																				// value
																				// .split(",")[0]
																				// +
																				// "</option>";
																				// });
																			});
															var htmlA = "<div class=\"input-append\"><div class=\"col-sm-3\"><select class=\"form-control\" id=\"beforeClass\" name=\"runBefore\"><option>请选择相应方法分类</option>"
																	+ addClass
																	+ "</select></div><div class=\"col-sm-3\"><select class=\"form-control\" id=\"beforeMethod\" name=\"runBefore\"><option>请选择方法</option></select></div><div class=\"col-sm-5\"><input class=\"form-control\" id=\"beforeArgs\"	name=\"runBefore\" placeholder=\"根据方法输入参数，以逗号隔开\" /></div><div><a class=\"glyphicon glyphicon-remove\" href=\"javascript:void(0)\" id=\"runBeforeDel\" style=\"line-height: 35px\"></a></div></div>";
															$("#runBeforeAll")
																	.prepend(
																			htmlA);
														},
														error : function(e) {
															alert("对不起，后台处理发生异常，请联系管理员!");
														}
													});
										} else {
											var addClass = "";
											var addMethod = "";
											$.each(addBefore, function(key,
													values) {
												addClass += "<option>" + key
														+ "</option>";
												// $
												// .each(
												// values,
												// function(
												// i,
												// value) {
												// addMethod += "<option
												// id=\"beforeOption\" title=\""
												// + value
												// .split(",")[1]
												// + "\">"
												// + value
												// .split(",")[0]
												// + "</option>";
												// });
											});
											var htmlA = "<div class=\"input-append\"><div class=\"col-sm-3\"><select class=\"form-control\" id=\"beforeClass\" name=\"runBefore\"><option>请选择相应方法分类</option>"
													+ addClass
													+ "</select></div><div class=\"col-sm-3\"><select class=\"form-control\" id=\"beforeMethod\" name=\"runBefore\"><option>请选择方法</option></select></div><div class=\"col-sm-5\"><input class=\"form-control\" id=\"beforeArgs\"	name=\"runBefore\" placeholder=\"根据方法输入参数，以逗号隔开\" /></div><div><a class=\"glyphicon glyphicon-remove\" href=\"javascript:void(0)\" id=\"runBeforeDel\" style=\"line-height: 35px\"></a></div></div>";
											$("#runBeforeAll").prepend(htmlA);
										}
									});
					var tempArrB = "";
					$("#runBeforeAll").on(
							"change",
							"#beforeClass",
							function() {
								var chose = $(this).children('option:selected')
										.val();
								var $next = $(this).parent().next().children();
								// alert("chose:"+chose);
								$.each(addBefore, function(key, value) {
									// alert("key:"+key);
									if (chose == key) {
										$next.empty();
										$next.append("<option>请选择方法</option>");
										tempArrB = value;
										$.each(value, function(i, v) {
											var v0 = v.split("#,#")[0];
											var v1 = v.split("#,#")[1];
											// alert(v1);
											$next.append("<option title='" + v1
													+ "'>" + v0 + "</option>");
										});
									}
								});
							});
					$("#runBeforeAll").on(
							"change",
							"#beforeMethod",
							function() {
								var choseM = $(this)
										.children('option:selected').val();
								var $next = $(this).parent().next().children();
								$.each(tempArrB, function(i, v) {
									if (v.split("#,#")[0] == choseM) {
										// $next.val(v.split(",")[2]);
										$next.attr("placeholder", v
												.split("#,#")[2]);
									}
								});
							});

					$("#runBeforeAll").on("click", "#runBeforeDel", function() {
						$(this).parent().parent().remove();
						// }
					});

					$("#runAfterAdd")
							.click(
									function() {
										if (addAfter == "") {
											// alert("添加类为空，发起请求！");
											$
													.ajax({
														type : "POST",
														url : "getInitAfter.action",
														data : "",
														dataType : "json",
														success : function(json) {
															// alert(json.initAfterJson);
															addAfter = jQuery
																	.parseJSON(json.initAfterJson);
															var addClass = "";
															var addMethod = "";
															$
																	.each(
																			addAfter,
																			function(
																					key,
																					values) {
																				addClass += "<option>"
																						+ key
																						+ "</option>";
//																				$
//																						.each(
//																								values,
//																								function(
//																										i,
//																										value) {
//																									addMethod += "<option title=\""
//																											+ value
//																													.split(",")[1]
//																											+ "\">"
//																											+ value
//																													.split(",")[0]
//																											+ "</option>";
//																								});
																			});
															var htmlA = "<div class=\"input-append\"><div class=\"col-sm-3\"><select class=\"form-control\" id=\"afterClass\" name=\"runAfter\"><option>请选择相应方法分类</option>"
																	+ addClass
																	+ "</select></div><div class=\"col-sm-3\"><select class=\"form-control\" id=\"afterMethod\" name=\"runAfter\"><option>请选择方法</option></select></div><div class=\"col-sm-5\"><input class=\"form-control\" id=\"afterArgs\"	name=\"runAfter\" placeholder=\"根据方法输入参数，以逗号隔开\" /></div><div><a class=\"glyphicon glyphicon-remove\" href=\"javascript:void(0)\" id=\"runAfterDel\" style=\"line-height: 35px\"></a></div></div>";
															$("#runAfterAll")
																	.prepend(
																			htmlA);
														},
														error : function(e) {
															alert("对不起，后台处理发生异常，请联系管理员!");
														}
													});
										} else {
											var addClass = "";
											var addMethod = "";
											$
													.each(
															addAfter,
															function(key,
																	values) {
																addClass += "<option>"
																		+ key
																		+ "</option>";
//																$
//																		.each(
//																				values,
//																				function(
//																						i,
//																						value) {
//																					addMethod += "<option title=\""
//																							+ value
//																									.split(",")[1]
//																							+ "\">"
//																							+ value
//																									.split(",")[0]
//																							+ "</option>";
//																				});
															});
											var htmlA = "<div class=\"input-append\"><div class=\"col-sm-3\"><select class=\"form-control\" id=\"afterClass\" name=\"runAfter\"><option>请选择相应方法分类</option>"
													+ addClass
													+ "</select></div><div class=\"col-sm-3\"><select class=\"form-control\" id=\"afterMethod\" name=\"runAfter\"><option>请选择方法</option></select></div><div class=\"col-sm-5\"><input class=\"form-control\" id=\"afterArgs\"	name=\"runAfter\" placeholder=\"根据方法输入参数，以逗号隔开\" /></div><div><a class=\"glyphicon glyphicon-remove\" href=\"javascript:void(0)\" id=\"runAfterDel\" style=\"line-height: 35px\"></a></div></div>";
											$("#runAfterAll").prepend(htmlA);
										}
										// var htmlA="<div
										// class=\"input-append\"><div
										// class=\"col-sm-5\"><select
										// class=\"form-control\"
										// id=\"afterClass\"
										// name=\"runAfter\"><option></option></select></div><div
										// class=\"col-sm-3\"><select
										// class=\"form-control\"
										// id=\"afterMethod\"
										// name=\"runAfter\"><option></option></select></div><div
										// class=\"col-sm-3\"><input
										// class=\"form-control\"
										// id=\"afterArgs\" name=\"runAfter\"
										// placeholder=\"根据方法输入参数，以逗号隔开\"
										// /></div><div><a class=\"glyphicon
										// glyphicon-remove\"
										// href=\"javascript:void(0)\"
										// id=\"runAfterDel\"
										// style=\"line-height:
										// 35px\"></a></div></div>";
										// $("#runAfterAll").prepend(htmlA);
									});
					
					var tempArrA = "";
					$("#runAfterAll").on(
							"change",
							"#afterClass",
							function() {
								var chose = $(this).children('option:selected')
										.val();
								var $next = $(this).parent().next().children();
								// alert("chose:"+chose);
								$.each(addAfter, function(key, value) {
									// alert("key:"+key);
									if (chose == key) {
										$next.empty();
										$next.append("<option>请选择方法</option>");
										tempArrA = value;
										$.each(value, function(i, v) {
											var v0 = v.split("#,#")[0];
											var v1 = v.split("#,#")[1];
											// alert(v1);
											$next.append("<option title='" + v1
													+ "'>" + v0 + "</option>");
										});
									}
								});
							});
					$("#runAfterAll").on(
							"change",
							"#afterMethod",
							function() {
								var choseM = $(this)
										.children('option:selected').val();
								var $next = $(this).parent().next().children();
								$.each(tempArrA, function(i, v) {
									if (v.split("#,#")[0] == choseM) {
										// $next.val(v.split(",")[2]);
										$next.attr("placeholder", v
												.split("#,#")[2]);
									}
								});
							});

					$("#runAfterAll").on("click", "#runAfterDel", function() {
						// alert("remove this");
						// if(confirm("确认删除?")){
						$(this).parent().parent().remove();
						// }
					});

					$("#headerAll")
							.on(
									"click",
									"#headerAdd",
									function() {
										var htmlA = "<div class=\"input-append\"><div class=\"col-sm-4\"><input class=\"form-control\" id=\"headerAttr\" name=\"headers\" placeholder=\"Hearder attribute key\" /></div><div class=\"col-sm-4\"><input class=\"form-control\" id=\"headerAttr\" name=\"headers\" placeholder=\"Value\" /></div><div><a class=\"glyphicon glyphicon-remove\" id=\"headerRemove\" href=\"javascript:void(0)\" style=\"line-height:35px\"></a></div></div>";
										$("#headerAll").prepend(htmlA);
									});
					$("#headerAll").on("click", "#headerRemove", function() {
						// alert("remove this");
						// if(confirm("确认删除?")){
						// $("#headerRemove").parent().parent().remove();
						$(this).parent().parent().remove();
						// }
					});

					$("#URLAll")
							.on(
									"click",
									"#URLAdd",
									function() {
										var htmlA = "<div class=\"input-append\"><div class=\"col-sm-4\"><input class=\"form-control\" id=\"URLAttr\" name=\"urlParams\" placeholder=\"URL parameter key\" /></div><div class=\"col-sm-4\"><input class=\"form-control\" id=\"URLAttr\" name=\"urlParams\" placeholder=\"Value\" /></div><div><a class=\"glyphicon glyphicon-remove\" id=\"URLRemove\" href=\"javascript:void(0)\" style=\"line-height:35px\"></a></div></div>";
										$("#URLAll").prepend(htmlA);
									});
					$("#URLAll").on("click", "#URLRemove", function() {
						// alert("remove this");
						// if(confirm("确认删除?")){
//						$("#URLRemove").parent().parent().remove();
						$(this).parent().parent().remove();
						// }
					});

					$("#xfuAll")
							.on(
									"click",
									"#nameValuePairAdd",
									function() {
										var htmlA = "<div class=\"input-append\"><div class=\"col-sm-4\"><input class=\"form-control\" id=\"xfuAttr\" name=\"nameValuePairs\" placeholder=\"Key\" /></div><div class=\"col-sm-4\"><input class=\"form-control\" id=\"xfuAttr\" name=\"nameValuePairs\" placeholder=\"Value\" /></div><div><a class=\"glyphicon glyphicon-remove\" id=\"xfuRemove\" href=\"javascript:void(0)\" style=\"line-height:35px\"></a></div></div>";
										$("#xfuAll").prepend(htmlA);
									});
					$("#xfuAll").on("click", "#xfuRemove", function() {
						// alert("remove this");
						// if(confirm("确认删除?")){
//						$("#xfuRemove").parent().parent().remove();
						$(this).parent().parent().remove();
						// }
					});

				});